From 2b38d14bf5662f17edd6c38b2ce04335326eeb05 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 30 Oct 2020 19:26:56 -0400 Subject: [PATCH] tests: Improve coverage for css data url parsing Cover the error conditions as well. --- testsuite/css/data.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/testsuite/css/data.c b/testsuite/css/data.c index 72533fcfb2..978be0e55e 100644 --- a/testsuite/css/data.c +++ b/testsuite/css/data.c @@ -58,6 +58,15 @@ Test tests[] = { { "charset_base64", "data:text/plain;charset=ISO-8859-5;base64,wOPh29DdILjW0ePb0OLe0g==", "text/plain", CONTENTS("Руслан Ижбулатов") }, + { "wrong_scheme", + "duda:,Hello", + NULL, NULL, 0 }, + { "missing_comma", + "data:text/plain;charset=ISO-8859-1:bla", + NULL, NULL, 0 }, + { "bad_escape", + "data:,abc%00", + NULL, NULL, -1 }, }; static void @@ -70,17 +79,25 @@ test_parse (gconstpointer data) bytes = gtk_css_data_url_parse (test->url, &mimetype, &error); - g_assert (bytes != NULL); - g_assert_no_error (error); - if (test->mimetype == NULL) - g_assert (mimetype == NULL); - else - g_assert_cmpstr (mimetype, ==, test->mimetype); - - g_assert_cmpmem (g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes), - test->contents, test->contents_len); + if (test->contents) + { + g_assert_nonnull (bytes); + g_assert_no_error (error); + if (test->mimetype == NULL) + g_assert (mimetype == NULL); + else + g_assert_cmpstr (mimetype, ==, test->mimetype); - g_bytes_unref (bytes); + g_assert_cmpmem (g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes), + test->contents, test->contents_len); + g_bytes_unref (bytes); + } + else + { + g_assert_null (bytes); + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME); + g_error_free (error); + } } int -- 2.30.2